'''
# selenium体验
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# 打开浏览器 浏览器最大化 输入网址全称 在搜索栏输入关键字-天气预报 点击搜索按钮 关闭浏览器
driver = webdriver.Chrome()

driver.maximize_window()
time.sleep(2)
driver.get('https://www.baidu.com')

time.sleep(1)
kw = driver.find_element(By.ID, 'kw')
kw.send_keys('天气预报')

time.sleep(3)
su=driver.find_element(By.ID,'su')
su.click()

time.sleep(2)
driver.quit()
'''
'''
# 移动端的打开方式 导入
# 准备配置项  创建对象  添加选项配置信息
# 打开浏览器，配置选项对象
##访问网址，退出浏览器

from selenium import webdriver
import time

mobileEmulation = {'deviceName': 'iPhone SE'}

options=webdriver.ChromeOptions()

# 添加选项配置信息
options.add_experimental_option("mobileEmulation",mobileEmulation)
# 打开浏览器，配置选项对象
driver=webdriver.Chrome(options=options)

driver.get('https://www.baidu.com')

time.sleep(4)
driver.quit()

'''

'''
# chrome驱动使用
#导入selenium
#打开浏览器
#退出浏览器
from selenium import webdriver
import time

driver=webdriver.Chrome()
time.sleep(3)
driver.quit()

#firefox驱动使用
# 导入selenium
# 打开firefox浏览器
# 退出浏览器
from selenium import webdriver
import time

driver = webdriver.Firefox()
time.sleep(3)
driver.quit()

'''
'''
#selenium面向过程
#导入selenium
#打开浏览器 输入网址全称 获取搜索框 输入关键字-天气预报
# 获取百度按钮  获取页面标题，并打印出来   检查python关键字是否在标题中
#关闭浏览器
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver=webdriver.Chrome()
time.sleep(2)
driver.get('https://www.baidu.com')

time.sleep(1)
kw=driver.find_element(By.ID,'kw')

time.sleep(3)
kw.send_keys('天气预报')
# kw.send_keys('python')
su=driver.find_element(By.ID,'su')
su.click()

time.sleep(3)
print(driver.title)


if 'python' in driver.title:
    print('ok')
else:
    print('no')

time.sleep(2)
driver.quit()
'''
'''
#selenium面向对象
# 导入
# 初始化对象属性  请求百度  搜索框输入内容  点击百度一下
# 作业  seconds秒
from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class TestCase:
    def __init__(self):
        self.driver = webdriver.Chrome()

    def get_baidu(self):
        # 请求 输入 点击
        self.driver.get('https://www.baidu.com')

        time.sleep(3)
        self.driver.find_element(By.ID, 'kw').send_keys('天气预报')

        time.sleep(2)
        self.driver.find_element(By.ID, 'su').click()

    def get_so(self):
        self.driver.get('https://www.so.com/')

        time.sleep(2)
        self.driver.find_element(By.ID, 'input').send_keys('天气预报')

        time.sleep(2)
        self.driver.find_element(By.ID, 'search-button').click()

    def quit(self, seconds=2):
        time.sleep(seconds)
        self.driver.quit()


if __name__ == '__main__':
    case = TestCase()
    # case.get_baidu()
    case.get_so()
    # case.quit()
'''
'''
#无头模式打开浏览器
#导入   选项对象，添加参数
#打开浏览器，设置选项
#请求百度 输出网页标题  退出浏览器
from selenium import webdriver
options=webdriver.ChromeOptions()
options.add_argument('-headless')
driver=webdriver.Chrome(options=options)

driver.get('https://www.baidu.com')

print(driver.title)

driver.quit()

'''
'''
# 浏览器操作
from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class BrowerOperation:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get('http://www.baidu.com')

    def quit(self, seconds=2):
        time.sleep(seconds)
        self.driver.quit()

    # 浏览器窗口大小  设置具体的尺寸
    def window_size(self):
        for i in range(2):
            time.sleep(2)
            self.driver.set_window_size(480, 800)

            time.sleep(2)
            self.driver.maximize_window()
            time.sleep(2)
            self.driver.minimize_window()

    # 浏览器前进和后退
    def forward_and_back(self):
        for i in range(2):
            # 先后退 再前进
            time.sleep(2)
            self.driver.back()

            time.sleep(2)
            self.driver.forward()

    def refresh(self):
        # 浏览器刷新
        time.sleep(2)
        self.driver.refresh()

    def close(self):
        # close关闭标签页
        # 获取新闻这个连接标签-链接文本定位方式
        time.sleep(2)
        news = self.driver.find_element(By.LINK_TEXT, '新闻')
        news.click()

        time.sleep(2)
        self.driver.close()


if __name__ == '__main__':
    browser = BrowerOperation
    # browser.window_size()
    # browser.forward_and_back()
    # browser.refresh()
    # browser.close()
    # browser.quit(5)
'''